package com.test.demo.annotation.proxy.http.handler;

import com.test.demo.annotation.proxy.http.annotation.HttpClient;
import com.test.demo.annotation.proxy.http.annotation.HttpMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.lang.reflect.Method;

/**
 * @ClassName DefaultMyFeginClientSupport
 * @Description
 * @Author laigl
 * @Date 2020/2/22 22:44
 **/
@Component
public class DefaultMyFeginClientSupport implements MyFeginClientSupport {

    @Autowired
    private RestTemplate restTemplate;

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) {

        HttpClient myFeginClientScanner = method.getDeclaringClass().getAnnotation(HttpClient.class);
        HttpMapping myFeginClientRequestMapping = method.getAnnotation(HttpMapping.class);

        String value = myFeginClientRequestMapping.value();
        if("test1".equals(value)){
            return "1";
        }else if("test2".equals(value)){
            return "2";
        }

        String s = restTemplate.getForObject(value,String.class);
        if(true){
            return s;
        }

        String result = null;
        if (args != null && args.length == 1) {

        }

        if (method.getReturnType() == String.class) {
            return result;
        }
        return null;

    }
}
